package lab03.Test03;
import java.io.*;
import java.util.RandomAccess;
import java.util.stream.Stream;

/**
 * Created by 李晓容 on 2017/12/10.
 */
public class Test {
    public static void main(String[] args) throws IOException {
        String path = "E:\\test.txt";
        FileOutputStream fileOutputStream = null;
        try {
            fileOutputStream = new FileOutputStream(path);
            //10101011字节
            fileOutputStream.write("Beijing欢迎你".getBytes());
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                fileOutputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        try {
            FileInputStream fileInputStream=new FileInputStream(path);
            int tmp;
            while((tmp=fileInputStream.read())!=-1){
                System.out.println((char)tmp);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        FileWriter fileWriter= null;
        try {
            fileWriter = new FileWriter("E:\\test.txt",true);
        } catch (IOException e) {
            e.printStackTrace();
        }
        PrintWriter printWriter=new PrintWriter(fileWriter);
        printWriter.println("我的学号是：1606101121");
        printWriter.close();
        try {
            fileWriter.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        RandomAccessFile randomAccessFile= null;

        try {
            randomAccessFile = new RandomAccessFile("E:\\test.txt","rw");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

        try {
            randomAccessFile.seek(randomAccessFile.length());
        } catch (IOException e) {
            e.printStackTrace();
        }
        randomAccessFile.close();
    }
}
